<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="embroot.css">
<TITLE>
Compiling and loading
</TITLE>
</HEAD>
<BODY >
<A HREF="embroot013.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="embroot012.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot015.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc31">4.2</A>&nbsp;&nbsp;Compiling and loading</H2>
It is strongly recommended to copy the makefile "Makefile.external"
provided in your installation directory under lib/$ARCH and adapt it
for your purposes.
<A NAME="@default71"></A>
If the makefile is not used, the command to compile a C source
with ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> library calls looks something like this:
<PRE CLASS="verbatim">
    % cc -G -I/usr/local/eclipse/include/sparc_sunos5
                -o eg_externals.so eg_externals.c
</PRE>or
<PRE CLASS="verbatim">
    % cc -shared -I/usr/local/eclipse/include/i386_linux
                -o eg_externals.so eg_externals.c
</PRE>If the external is to be used in a standalone ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>,
it is possible to dynamically load it
using the <A HREF="../bips/kernel/externals/load-1.html"><B>load/1</B></A><A NAME="@default72"></A>
predicate:
<PRE CLASS="verbatim">
    load("eg_externals.so")
</PRE>On older UNIX platforms without dynamic loading, the following method
may work. Compile the source using
<PRE CLASS="verbatim">
    % cc -c -I/usr/local/eclipse/include/sparc_sunos5 eg_externals.c
</PRE>and load it with a command like
<PRE CLASS="verbatim">
    load("eg_externals.o -lg -lm")
</PRE>The details may vary depending on what compiler and operating system
you use. Refer to the Makefile.external for details.<BR>
<BR>
Once the object file containing the C function has been loaded into
ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>, the link between the function and a predicate name
is made with
<A HREF="../bips/kernel/externals/external-2.html"><B>external/2</B></A><A NAME="@default73"></A>
<PRE CLASS="verbatim">
    external(sumlist/2, p_sumlist)
</PRE>The new predicate can now be called like other predicates.
Note that the 
<A HREF="../bips/kernel/externals/external-2.html"><B>external/2</B></A><A NAME="@default74"></A>
declaration must precede any call to the declared predicate,
otherwise the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> compiler will issue an <EM>inconsistent
redefinition</EM> error. Alternatively, the
<A HREF="../bips/kernel/externals/external-1.html"><B>external/1</B></A><A NAME="@default75"></A>
forward declaration can be used to prevent this.<BR>
<BR>
If the external is needed in the context of an ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> which is itself
embedded in a C/C++ host program, then the external code can be
compiled/linked together with the host program, and the link between function
and predicate name can alternatively be made by calling the C function
ec_external(), e.g.
<PRE CLASS="verbatim">
    ec_external(ec_did("sumlist",2), p_sumlist, ec_did("eclipse"))
</PRE>This must be done after the embedded ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> has been initialised
(and after the module that is supposed to contain the external predicate
has already been created).<BR>
<BR>
<HR>
<A HREF="embroot013.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="embroot012.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot015.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
